import Euclid.*;
import java.util.*;
import java.math.*;

public class EuclidExport implements EuclidExporter {
	
	public String[] getExports()
	{
		return new String[] { "factor" };
	}
	
	public VarType factor(VarType a)
	{
		if (a instanceof SymbVarType)
			return factor(((SymbVarType)a).val);
		else if (a instanceof IntVarType)
		{
			IntVarType i = (IntVarType)a;
			ArrayList<Factor.ExpNumber> factors = Factor.factor(i.val);
			Factor.ExpNumber n = factors.get(0);  // must have at least one factor...
			String formula = n.base.toString();
			if (n.exponent.compareTo(BigInteger.ONE) > 0) formula += "^" + n.exponent;
			for (int j = 1; j < factors.size(); j++)
			{
				n = factors.get(j);
				formula += " \\times " + n.base;
				if (n.exponent.compareTo(BigInteger.ONE) > 0) formula += "^" + n.exponent;
			}
			return new IntVarType(i.val, formula);
		}
		else
			return null;
	}

}
